/**
 * Copyright 2009-2011 xiaonei.com All right reserved.
 * This software is the confidential and proprietary information of Xiaonei.com ("Confidential Information"). 
 * You shall not disclose such Confidential Information and shall use it only in accordance with the terms of the license agreement you entered into with Xiaonei.com.
 * Create by XiaoNeiAntiSpamTeam
 *
 */

package com.xiaonei.netty.hello;

import java.net.InetSocketAddress;
import java.util.concurrent.Executors;

import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;

/**
 * @ClassName: HelloClient
 * @Description: TODO
 * @author shaohui.liu shaohui.liu@opi-corp.com
 * @date Apr 8, 2010 4:08:55 PM
 * 
 */
public class HelloClient {

    public static void main(String[] args) throws Exception {

        String host = "127.0.0.1";

        int port = 8888;

        int firstMessageSize = 1;

        // Configure the client.
        ClientBootstrap bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors
                .newCachedThreadPool(), Executors.newCachedThreadPool()));

        // Set up the default event pipeline.
        HelloClientHandler handler = new HelloClientHandler(firstMessageSize);

        bootstrap.getPipeline().addLast("handler", handler);

        // Start the connection attempt.
        ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));

        // Wait until the connection is closed or the connection attempt fails.
        future.getChannel().getCloseFuture().awaitUninterruptibly();

        // Shut down thread pools to exit.
        bootstrap.releaseExternalResources();

        System.exit(0);
    }
}
